from spe import registerPreHook, unregisterPreHook
from playerlib import getPlayer
from superdice.superdice import registerRoll, unregisterRoll, players

def unload():
    unregisterPreHook('player_falldamage', player_falldamage_pre)
    unregisterRoll(diceRoll)

def player_spawn(ev):
    players[ev['userid']]['antifall'] = False

def player_falldamage_pre(ev):
    userid = str(ev['userid'])
    if not players[userid]['antifall']:
        return

    getPlayer(userid).health += int(str(ev['damage']).split('.')[0])

def diceRoll(userid, player, eplayer):
    players[userid]['antifall'] = True

registerPreHook('player_falldamage', player_falldamage_pre)

registerRoll(diceRoll, 'antifall')
